/**
 * Copyright 2017 SmartBear Software
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.wapache.openapi.v3.models.security;

/**
 * <h4><a name="%3Ca-name=%22securityschemeobject%22%3E%3C/a%3Esecurity-scheme-object" class="md-header-anchor"></a><a name="securitySchemeObject"></a><span>Security Scheme Object</span></h4>
 * <p><span>Defines a security scheme that can be used by the operations.</span>
 * <span>Supported schemes are HTTP authentication, an API key (either as a header or as a query parameter), OAuth2&#39;s common flows (implicit, password, application and access code) as defined in </span><a href='https://tools.ietf.org/html/rfc6749'><span>RFC6749</span></a><span>, and </span><a href='https://tools.ietf.org/html/draft-ietf-oauth-discovery-06'><span>OpenID Connect Discovery</span></a><span>.</span></p>
 * <h5><a name="fixed-fields" class="md-header-anchor"></a><span>Fixed Fields</span></h5>
 * <figure><table>
 * <thead>
 * <tr><th><span>Field Name</span></th><th style='text-align:center;' ><span>Type</span></th><th><span>Applies To</span></th><th><span>Description</span></th></tr></thead>
 * <tbody><tr><td><a name="securitySchemeType"></a><span>type</span></td><td style='text-align:center;' ><code>string</code></td><td><span>Any</span></td><td><strong><span>REQUIRED</span></strong><span>. The type of the security scheme. Valid values are </span><code>&quot;apiKey&quot;</code><span>, </span><code>&quot;http&quot;</code><span>, </span><code>&quot;oauth2&quot;</code><span>, </span><code>&quot;openIdConnect&quot;</code><span>.</span></td></tr><tr><td><a name="securitySchemeDescription"></a><span>description</span></td><td style='text-align:center;' ><code>string</code></td><td><span>Any</span></td><td><span>A short description for security scheme. </span><a href='http://spec.commonmark.org/'><span>CommonMark syntax</span></a><span> MAY be used for rich text representation.</span></td></tr><tr><td><a name="securitySchemeName"></a><span>name</span></td><td style='text-align:center;' ><code>string</code></td><td><code>apiKey</code></td><td><strong><span>REQUIRED</span></strong><span>. The name of the header, query or cookie parameter to be used.</span></td></tr><tr><td><a name="securitySchemeIn"></a><span>in</span></td><td style='text-align:center;' ><code>string</code></td><td><code>apiKey</code></td><td><strong><span>REQUIRED</span></strong><span>. The location of the API key. Valid values are </span><code>&quot;query&quot;</code><span>, </span><code>&quot;header&quot;</code><span> or </span><code>&quot;cookie&quot;</code><span>.</span></td></tr><tr><td><a name="securitySchemeScheme"></a><span>scheme</span></td><td style='text-align:center;' ><code>string</code></td><td><code>http</code></td><td><strong><span>REQUIRED</span></strong><span>. The name of the HTTP Authorization scheme to be used in the </span><a href='https://tools.ietf.org/html/rfc7235#section-5.1'><span>Authorization header as defined in RFC7235</span></a><span>.</span></td></tr><tr><td><a name="securitySchemeBearerFormat"></a><span>bearerFormat</span></td><td style='text-align:center;' ><code>string</code></td><td><code>http</code><span> (</span><code>&quot;bearer&quot;</code><span>)</span></td><td><span>A hint to the client to identify how the bearer token is formatted.  Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes.</span></td></tr><tr><td><a name="securitySchemeFlows"></a><span>flows</span></td><td style='text-align:center;' ><a href='#'><span>OAuth Flows Object</span></a></td><td><code>oauth2</code></td><td><strong><span>REQUIRED</span></strong><span>. An object containing configuration information for the flow types supported.</span></td></tr><tr><td><a name="securitySchemeOpenIdConnectUrl"></a><span>openIdConnectUrl</span></td><td style='text-align:center;' ><code>string</code></td><td><code>openIdConnect</code></td><td><strong><span>REQUIRED</span></strong><span>. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.</span></td></tr></tbody>
 * </table></figure>
 * <p><span>This object MAY be extended with </span><a href='#'><span>Specification Extensions</span></a><span>.</span></p>
 * <h5><a name="security-scheme-object-example" class="md-header-anchor"></a><span>Security Scheme Object Example</span></h5>
 * <h6><a name="basic-authentication-sample" class="md-header-anchor"></a><span>Basic Authentication Sample</span></h6>
 * <pre><code class='language-json' lang='json'>{
 *   &quot;type&quot;: &quot;http&quot;,
 *   &quot;scheme&quot;: &quot;basic&quot;
 * }
 * </code></pre>
 * <pre><code class='language-yaml' lang='yaml'>type: http
 * scheme: basic
 * </code></pre>
 * <h6><a name="api-key-sample" class="md-header-anchor"></a><span>API Key Sample</span></h6>
 * <pre><code class='language-json' lang='json'>{
 *   &quot;type&quot;: &quot;apiKey&quot;,
 *   &quot;name&quot;: &quot;api_key&quot;,
 *   &quot;in&quot;: &quot;header&quot;
 * }
 * </code></pre>
 * <pre><code class='language-yaml' lang='yaml'>type: apiKey
 * name: api_key
 * in: header
 * </code></pre>
 * <h6><a name="jwt-bearer-sample" class="md-header-anchor"></a><span>JWT Bearer Sample</span></h6>
 * <pre><code class='language-json' lang='json'>{
 *   &quot;type&quot;: &quot;http&quot;,
 *   &quot;scheme&quot;: &quot;bearer&quot;,
 *   &quot;bearerFormat&quot;: &quot;JWT&quot;,
 * }
 * </code></pre>
 * <pre><code class='language-yaml' lang='yaml'>type: http
 * scheme: bearer
 * bearerFormat: JWT
 * </code></pre>
 * <h6><a name="implicit-oauth2-sample" class="md-header-anchor"></a><span>Implicit OAuth2 Sample</span></h6>
 * <pre><code class='language-json' lang='json'>{
 *   &quot;type&quot;: &quot;oauth2&quot;,
 *   &quot;flows&quot;: {
 *     &quot;implicit&quot;: {
 *       &quot;authorizationUrl&quot;: &quot;https://example.com/api/oauth/dialog&quot;,
 *       &quot;scopes&quot;: {
 *         &quot;write:pets&quot;: &quot;modify pets in your account&quot;,
 *         &quot;read:pets&quot;: &quot;read your pets&quot;
 *       }
 *     }
 *   }
 * }
 * </code></pre>
 * <pre><code class='language-yaml' lang='yaml'>type: oauth2
 * flows:
 *   implicit:
 *     authorizationUrl: https://example.com/api/oauth/dialog
 *     scopes:
 *       write:pets: modify pets in your account
 *       read:pets: read your pets
 * </code></pre>
 * @see "https://github.com/OAI/OpenAPI-Specification/blob/3.0.1/versions/3.0.1.md#securitySchemeObject"
 */

public class SecurityScheme {
    /**
     * Gets or Sets type
     */
    public enum Type {
        APIKEY("apiKey"),
        HTTP("http"),
        OAUTH2("oauth2"),
        OPENIDCONNECT("openIdConnect");

        private String value;

        Type(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return String.valueOf(value);
        }
    }

    private Type type = null;
    private String description = null;
    private String name = null;
    private String $ref = null;

    /**
     * Gets or Sets in
     */
    public enum In {
        COOKIE("cookie"),

        HEADER("header"),

        QUERY("query");

        private String value;

        In(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return String.valueOf(value);
        }
    }

    private In in = null;
    private String scheme = null;
    private String bearerFormat = null;
    private OAuthFlows flows = null;
    private String openIdConnectUrl = null;
    private java.util.Map<String, Object> extensions = null;

    /**
     * returns the type property from a SecurityScheme instance.
     *
     * @return Type type
     **/

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public SecurityScheme type(Type type) {
        this.type = type;
        return this;
    }

    /**
     * returns the description property from a SecurityScheme instance.
     *
     * @return String description
     **/

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public SecurityScheme description(String description) {
        this.description = description;
        return this;
    }

    /**
     * returns the name property from a SecurityScheme instance.
     *
     * @return String name
     **/

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SecurityScheme name(String name) {
        this.name = name;
        return this;
    }

    /**
     * returns the in property from a SecurityScheme instance.
     *
     * @return In in
     **/

    public In getIn() {
        return in;
    }

    public void setIn(In in) {
        this.in = in;
    }

    public SecurityScheme in(In in) {
        this.in = in;
        return this;
    }

    /**
     * returns the scheme property from a SecurityScheme instance.
     *
     * @return String scheme
     **/

    public String getScheme() {
        return scheme;
    }

    public void setScheme(String scheme) {
        this.scheme = scheme;
    }

    public SecurityScheme scheme(String scheme) {
        this.scheme = scheme;
        return this;
    }

    /**
     * returns the bearerFormat property from a SecurityScheme instance.
     *
     * @return String bearerFormat
     **/

    public String getBearerFormat() {
        return bearerFormat;
    }

    public void setBearerFormat(String bearerFormat) {
        this.bearerFormat = bearerFormat;
    }

    public SecurityScheme bearerFormat(String bearerFormat) {
        this.bearerFormat = bearerFormat;
        return this;
    }

    /**
     * returns the flows property from a SecurityScheme instance.
     *
     * @return OAuthFlows flows
     **/

    public OAuthFlows getFlows() {
        return flows;
    }

    public void setFlows(OAuthFlows flows) {
        this.flows = flows;
    }

    public SecurityScheme flows(OAuthFlows flows) {
        this.flows = flows;
        return this;
    }

    /**
     * returns the openIdConnectUrl property from a SecurityScheme instance.
     *
     * @return String openIdConnectUrl
     **/

    public String getOpenIdConnectUrl() {
        return openIdConnectUrl;
    }

    public void setOpenIdConnectUrl(String openIdConnectUrl) {
        this.openIdConnectUrl = openIdConnectUrl;
    }

    public SecurityScheme openIdConnectUrl(String openIdConnectUrl) {
        this.openIdConnectUrl = openIdConnectUrl;
        return this;
    }

    public java.util.Map<String, Object> getExtensions() {
        return extensions;
    }

    public void addExtension(String name, Object value) {
        if (name == null || name.isEmpty() || !name.startsWith("x-")) {
            return;
        }
        if (this.extensions == null) {
            this.extensions = new java.util.LinkedHashMap<>();
        }
        this.extensions.put(name, value);
    }

    public void setExtensions(java.util.Map<String, Object> extensions) {
        this.extensions = extensions;
    }

    public SecurityScheme extensions(java.util.Map<String, Object> extensions) {
        this.extensions = extensions;
        return this;
    }

    /**
     * returns the $ref property from an SecurityScheme instance.
     *
     * @return String $ref
     **/
    public String get$ref() {
        return $ref;
    }

    public void set$ref(String $ref) {
        if ($ref != null && ($ref.indexOf('.') == -1 && $ref.indexOf('/') == -1)) {
            $ref = "#/components/securitySchemes/" + $ref;
        }
        this.$ref = $ref;
    }

    public SecurityScheme $ref(String $ref) {
        set$ref($ref);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof SecurityScheme)) {
            return false;
        }

        SecurityScheme that = (SecurityScheme) o;

        if (type != that.type) {
            return false;
        }
        if (description != null ? !description.equals(that.description) : that.description != null) {
            return false;
        }
        if (name != null ? !name.equals(that.name) : that.name != null) {
            return false;
        }
        if ($ref != null ? !$ref.equals(that.$ref) : that.$ref != null) {
            return false;
        }
        if (in != that.in) {
            return false;
        }
        if (scheme != null ? !scheme.equals(that.scheme) : that.scheme != null) {
            return false;
        }
        if (bearerFormat != null ? !bearerFormat.equals(that.bearerFormat) : that.bearerFormat != null) {
            return false;
        }
        if (flows != null ? !flows.equals(that.flows) : that.flows != null) {
            return false;
        }
        if (openIdConnectUrl != null ? !openIdConnectUrl.equals(that.openIdConnectUrl) : that.openIdConnectUrl != null) {
            return false;
        }
        return extensions != null ? extensions.equals(that.extensions) : that.extensions == null;
    }

    @Override
    public int hashCode() {
        int result = type != null ? type.hashCode() : 0;
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + ($ref != null ? $ref.hashCode() : 0);
        result = 31 * result + (in != null ? in.hashCode() : 0);
        result = 31 * result + (scheme != null ? scheme.hashCode() : 0);
        result = 31 * result + (bearerFormat != null ? bearerFormat.hashCode() : 0);
        result = 31 * result + (flows != null ? flows.hashCode() : 0);
        result = 31 * result + (openIdConnectUrl != null ? openIdConnectUrl.hashCode() : 0);
        result = 31 * result + (extensions != null ? extensions.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class SecurityScheme {\n");

        sb.append("    type: ").append(toIndentedString(type)).append("\n");
        sb.append("    description: ").append(toIndentedString(description)).append("\n");
        sb.append("    name: ").append(toIndentedString(name)).append("\n");
        sb.append("    in: ").append(toIndentedString(in)).append("\n");
        sb.append("    scheme: ").append(toIndentedString(scheme)).append("\n");
        sb.append("    bearerFormat: ").append(toIndentedString(bearerFormat)).append("\n");
        sb.append("    flows: ").append(toIndentedString(flows)).append("\n");
        sb.append("    openIdConnectUrl: ").append(toIndentedString(openIdConnectUrl)).append("\n");
        sb.append("    $ref: ").append(toIndentedString($ref)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    /**
     * Convert the given object to string with each line indented by 4 spaces
     * (except the first line).
     */
    private String toIndentedString(Object o) {
        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n    ");
    }

}

